package cac.fenjian.resource.inStoreroom.util;

import cac.fenjian.resource.AoTask.MsTaskPackage.dao.MsTaskCheckOperDao;
import cac.fenjian.resource.AoTask.MsTaskPackage.dao.MsTaskPackageDao;
import cac.fenjian.resource.PointPackageSort.dao.PointPackageDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
@Slf4j
@Component
public class GkLogTaskCreateUtil {
    @Autowired
    private MsTaskPackageDao msTaskPackageDao;
    @Autowired
    private PointPackageDao pointPackageDao;
    @Autowired
    private MsTaskCheckOperDao msTaskCheckOperDao;
    @Value("${pathProperty.isTest}")
    private boolean isTest;
    /***
     * 创建下一个工作包任务
     * */
    public void createNextPackageTask(String IP){

        String consoleStatus=msTaskCheckOperDao.searchConsole(IP);
        if("2".equals(consoleStatus)){
            return;
        }

        //判断当前工作包任务数量是否小于等于2  待补充
        int taskCnt = pointPackageDao.queryPackageUnCreateTaskCnt(IP);
        if(taskCnt>2){//如果当前工作包存在的未创建任务数量大于2，则不创建下一个工作包任务
            return ;
        }
        List<HashMap> rsl = msTaskPackageDao.searchCurrentPackage(IP);
        if(rsl.size()==0){
            return ;
        }
        try{
            String packageId = null;
            HashMap pack = rsl.get(0);
            packageId = (String) pack.get("MSTASKPACKAGEID");
            HashMap map = new HashMap();
            map.put("i_ip", IP);
            map.put("i_package_id", packageId);
            log.info("存储过程参数" + map.toString());
            //声明分拣操作
            map.put("func", "sort");
            map.put("gzb_location", "");
            map.put("hcx_location", "");
            if (isTest) {
                pointPackageDao.callCreateTaskTest(map);
            } else {
                pointPackageDao.callCreateTask(map);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
